/*
 * SiSsingleton.h
 *
 *  Created on: May 4, 2013
 *      Author: dsweeney
 */

#ifndef SISSINGLETON_H_
#define SISSINGLETON_H_

#define NUM_SLOTS 20

#include <pthread.h>
#include <vector>
#include "../CommonLib/CommonTypesLib.h"

/*
This is going to be a multi-threaded effort.
1. thread to control frame access and slot timing
*/
class SiSsingleton
{
private:
	SiSsingleton();
	~SiSsingleton();

	void initMutexes(void);
	void initSlotStates(void);
	void destroyMutexes(void);

	//an array of mutexes to control access to each slot
	//initial to use a lock to block goal is be able to use a try lock
	//and record when the MDL misses a slot start event
	pthread_mutex_t* mutexes;
	//will be used to send the frame start event
	std::vector <pthread_mutex_t*> frameStartEvent;
	CommonLibTypes::slot_state_t* slotStates;
	int numNodes;
public:
	static SiSsingleton* instance();
	short pushPacket(CommonLibTypes::packet_t packet);
	CommonLibTypes::packet_t pullPacket(void);
	void waitForSlotStartEvent(void);
	void setNumNodes(int);
	pthread_mutex_t* addNode(int);
};


#endif /* SISSINGLETON_H_ */
